<%@ Page Language="C#" MasterPageFile="~/MasterDefault.master" AutoEventWireup="true"
    StylesheetTheme="Default" Inherits="TeamTime.UsersForm" Title="Manage security - Users"
    CodeBehind="~/usersForm.aspx.cs" %>

<%@ Register Src="LabelWithTimedMsg.ascx" TagName="LabelWithTimedMsg" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true">
        <Services>
            <asp:ServiceReference Path="AutoComplete.asmx" />
        </Services>
    </asp:ScriptManager>
    <%--  <clib:UpdatePanelExtender runat="server" ID="UpdatePanelExtender1" UpdateMode="Conditional">
        <ContentTemplate>--%>
    <br />
    <h3>
        Users</h3>
    User Group:
    <asp:DropDownList ID="ddlUserGroups" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlUserGroups_SelectedIndexChanged">
        <asp:ListItem Value="0" Selected="true">All User Groups</asp:ListItem>
    </asp:DropDownList>
    &nbsp;<asp:LinkButton ID="LinkButton1" OnClick="AddNew_Click" runat="server" Text="Add new user"
        CausesValidation="False"></asp:LinkButton>&nbsp;&nbsp;&nbsp;
    <uc1:LabelWithTimedMsg ID="LabelWithTimedMsg1" runat="server" />
    <asp:Label ID="Message" runat="server" ForeColor="Red" EnableViewState="False"></asp:Label>
    <asp:DataGrid ID="DataGrid1" runat="server" OnPageIndexChanged="DataGrid_Page" PageSize="15"
        AllowPaging="true" DataKeyField="ID" AutoGenerateColumns="False" OnCancelCommand="DataGrid_Cancel"
        OnUpdateCommand="DataGrid_Update" OnEditCommand="DataGrid_Edit" OnItemCommand="DataGrid_ItemCommand"
        AllowSorting="true" SkinID="GridView" OnSortCommand="DataGrid1_SortCommand">
        <Columns>
            <asp:TemplateColumn Visible="False" HeaderText="ID">
                <ItemTemplate>
                    <asp:Label ID="lblUserID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtUserID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'
                        MaxLength="4" Width="12px">
                    </asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="First Name" SortExpression="FirstName, LastName">
                <ItemTemplate>
                    <asp:Label ID="lblFirstName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FirstName") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtFirstName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FirstName") %>'
                        Width="86px" MaxLength="100">
                    </asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqValEditFirstName" runat="server" ControlToValidate="txtFirstName"
                        ErrorMessage="* Required" Display="Dynamic"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="Last Name" SortExpression="LastName, FirstName">
                <ItemTemplate>
                    <asp:Label ID="lblLastName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LastName") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtLastName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LastName") %>'
                        Width="86px" MaxLength="100">
                    </asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqValEditLastName" runat="server" ControlToValidate="txtLastName"
                        ErrorMessage="* Required" Display="Dynamic"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="Login Code">
                <ItemTemplate>
                    <asp:Label ID="lblLoginCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LoginCode") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtLoginCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LoginCode") %>'
                        Width="86px" MaxLength="40">
                    </asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqValEditLoginCode" runat="server" ControlToValidate="txtLoginCode"
                        ErrorMessage="* Required" Display="Dynamic"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn Visible="False" HeaderText="Password">
                <ItemTemplate>
                    <asp:Label ID="lblPassword" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Password") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtPassword" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Password") %>'
                        Width="86px" MaxLength="100" TextMode="Password" Enabled="False">
                    </asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqValEditPassword" runat="server" ControlToValidate="txtPassword"
                        ErrorMessage="* Required" Display="Dynamic"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="Default User Group">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlDefaultUserGroupID1" runat="server" DataTextField="UserGroup"
                        DataValueField="ID" DataSource="<%# dsUserGroups%>" Width="180px" SelectedIndex='<%# StillVoiceCommon.Functions.DropDownSelIndex(dsUserGroups ,Convert.ToInt32(DataBinder.Eval(Container, "DataItem.DefaultUserGroupID")), "ID") %>'>
                    </asp:DropDownList>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlDefaultUserGroupID" runat="server" DataTextField="UserGroup"
                        DataValueField="ID" DataSource="<%# dsUserGroups%>" Width="180px" SelectedIndex='<%# StillVoiceCommon.Functions.DropDownSelIndex(dsUserGroups ,Convert.ToInt32(DataBinder.Eval(Container, "DataItem.DefaultUserGroupID")), "ID") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn Visible="False" HeaderText="Std Hourly Rate">
                <ItemTemplate>
                    <asp:Label ID="lblStandardHourlyRate" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.StandardHourlyRate") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtStandardHourlyRate" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.StandardHourlyRate") %>'
                        Width="58px" MaxLength="8">
                    </asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="Email">
                <ItemTemplate>
                    <asp:Label ID="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Email") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtEmail" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Email") %>'
                        Width="117px" MaxLength="50">
                    </asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="Inactive Date" SortExpression="InactiveDate desc">
                <ItemTemplate>
                    <asp:Label ID="lblInactiveDate" runat="server" Text='<%# StillVoiceCommon.Functions.editGridDate(DataBinder.Eval(Container, "DataItem.InactiveDate")) %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtInactiveDate" runat="server" Text='<%# StillVoiceCommon.Functions.editGridDate(DataBinder.Eval(Container, "DataItem.InactiveDate")) %>'
                        Width="74px" MaxLength="8">
                    </asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateColumn>
            <%--<asp:TemplateColumn HeaderText="Read Only">
							<ItemTemplate>
								<asp:CheckBox id=CheckBox1 runat="server" Checked='<%# DataBinder.Eval(Container, "DataItem.ReadOnly") %>' Enabled="False">
								</asp:CheckBox>
							</ItemTemplate>
							<EditItemTemplate>
								<asp:CheckBox id=chkreadonly runat="server" Checked='<%# DataBinder.Eval(Container, "DataItem.ReadOnly") %>'>
								</asp:CheckBox>
							</EditItemTemplate>
						</asp:TemplateColumn>--%>
            <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="&lt;br&gt;Cancel"
                EditText="Edit"></asp:EditCommandColumn>
            <asp:ButtonColumn Visible="False" Text="Delete" CommandName="Delete"></asp:ButtonColumn>
            <asp:ButtonColumn Text="Reset Password" CommandName="ResetPassword"></asp:ButtonColumn>
            <asp:TemplateColumn HeaderText="            ">
                <ItemTemplate>
                    <a href='javascript:popupUserGroupsForm(<%# DataBinder.Eval(Container, "DataItem.ID")%>)'>
                        Groups</a>
                </ItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="            " Visible="false">
                <ItemTemplate>
                    <a href='javascript:popupUserCompaniesForm(<%# DataBinder.Eval(Container, "DataItem.ID")%>)'>
                        Companies</a>
                </ItemTemplate>
            </asp:TemplateColumn>
        </Columns>
        <PagerStyle HorizontalAlign="Center" Mode="NumericPages"></PagerStyle>
    </asp:DataGrid>

    <script type="text/javascript">
        function popupUserGroupsForm(id) {
            var url = 'UsersGroups.aspx?id=' + id + '&mode=popup';
            var pop = window.open(url, 'user', 'location=0,scrollbars=1,resizable=1,status=1,width=750,height=580');
            pop.focus();
        }
        function popupUserCompaniesForm(id) {
            var url = 'UsersCompanies.aspx?id=' + id + '&mode=popup';
            var pop = window.open(url, 'user', 'location=0,scrollbars=1,resizable=1,status=1,width=750,height=580');
            pop.focus();
        }
    </script>

    </ContentTemplate> </clib:UpdatePanelExtender>
</asp:Content>
